package com.young.dubbo.framework;

import com.young.dubbo.protocol.dubbo.DubboProtocol;
import com.young.dubbo.protocol.http.HttpProtocol;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 协议工厂，根据启动参数获取指定协议实现
 */
public class ProtocolFactory {

    private static Logger logger = LoggerFactory.getLogger(ProtocolFactory.class);

    public static Protocol getProtocol(){
        String protocol = System.getProperty("protocol");
        logger.info("当前使用协议：{}", protocol);
        switch (protocol){
            case "http":
                return new HttpProtocol();
            case "dubbo":
                return new DubboProtocol();
            default:
                throw new RuntimeException("不支持该协议");
        }
    }
}
